#include <string>
#include "atomic.h"
#include "message.h"
#include "mainsimu.h"
#include "strutil.h"
#include "../HeadFile/ERP_DB_processing_1_model.h"


/**** the Constructor ****/
ERP_DB_processing_1_model::ERP_DB_processing_1_model( const string &name)
: Atomic( name )
, ERP_DB_1_stream_DO( this->addInputPort( "ERP_DB_1_stream_DO") )
, ERP_DB_1_stream_OP( this->addOutputPort( "ERP_DB_1_stream_OP") )
, ERP_DB_1_stream_DB( this->addOutputPort( "ERP_DB_1_stream_DB") )
{

		
	string tmpval1(MainSimulator::Instance().getParameter( this->description(), "ERP_DB_1_stream_DO_yield_val" ));
	string tmpval2(MainSimulator::Instance().getParameter( this->description(), "ERP_DB_1_stream_DB_yield_val" ));

	ERP_DB_1_stream_DO_yield_val = str2float(tmpval1);
	ERP_DB_1_stream_DB_yield_val = str2float(tmpval2);

		
		
}


/*** the initFunction ***/
Model &ERP_DB_processing_1_model::initFunction()
{

		
	count = 0;
	delay = "00:00:00:00";
	passivate();
	return *this;
		
		
}

/*** the externalFunction ***/
Model &ERP_DB_processing_1_model::externalFunction( const ExternalMessage &msg )
{

			
	if( msg.port() == ERP_DB_1_stream_DO ){
		ERP_DB_1_stream_DO_flowrate = msg.value();
		count = 1;
		holdIn( active, delay);
	}
	return *this;
		
		
}

/*** the internalFunction ***/
Model &ERP_DB_processing_1_model::internalFunction( const InternalMessage &msg )
{

			
	passivate();
	return *this;
		
		
}

/*** the outputFunction ***/
Model &ERP_DB_processing_1_model::outputFunction( const InternalMessage &msg )
{

			
	if(count == 1)
	{
		count = 0;
		ERP_DB_1_stream_DB_flowrate = ERP_DB_1_stream_DO_flowrate * ERP_DB_1_stream_DB_yield_val;
		sendOutput( msg.time(), ERP_DB_1_stream_OP, ERP_DB_1_stream_DO_flowrate);
		sendOutput( msg.time(), ERP_DB_1_stream_DB, ERP_DB_1_stream_DB_flowrate);
	}
	return *this;
		
		
}

